{template 'header', 'member'}
<div id="head-bar">
<div class="head-bar">
<div class="head-bar-back">
<a href="{$back_link}" data-direction="reverse"><img src="{DT_MOB}static/img/icon-back.png" width="24" height="24"/><span>返回</span></a>
</div>
<div class="head-bar-title">{$MOD[name]}{if $action=='add'}发布{elseif $action=='edit'}修改{else}管理{/if}</div>
<div class="head-bar-right">
{if $action=='add' || $action=='edit'}
<a href="?mid={$mid}"><span>取消</span></a>
{else}
<a href="?mid={$mid}&action=add"><span>发布</span></a>
{/if}
</div>
</div>
<div class="head-bar-fix"></div>
</div>

{if $action=='add' || $action=='edit'}
<script type="text/javascript" src="{DT_MOB}static/lib/webuploader.min.js"></script>
<div class="ui-form">
<iframe src="" name="send" id="send" style="display:none;"></iframe>
<form method="post" action="?" id="dform" target="send" data-ajax="false" onsubmit="return check();">
<input type="hidden" name="action" value="{$action}"/>
<input type="hidden" name="mid" value="{$mid}"/>
<input type="hidden" name="itemid" value="{$itemid}"/>
<input type="hidden" name="forward" value="{$forward}"/>
<input type="hidden" name="post[linkurl]" value="{$linkurl}"/>

<p>所属分类<em>*</em><b id="dcatid"></b></p>
<div>{ajax_category_select('post[catid]', '选择分类', $catid, $moduleid)}</div>


<p>{$MOD[name]}名称<em>*</em><b id="dtitle"></b></p>
<div><input name="post[title]" type="text" id="title" value="{$title}"/></div>

<p>商品价格<em>*</em><b id="dprice"></b></p>
<div>
	<table cellspacing="1">
		<tr>
			<th>数量</th>
			<th>价格</th>
		</tr>
		<tr>
			<td style="width:40%;"><input name="post[step][a1]" type="text" value="{$a1}" id="a1"/></td>
			<td style="width:40%;"><input name="post[step][p1]" type="text" value="{$p1}" id="p1"/></td>
			<td style="display:none;" id="p_a_1"></td>
			<td style="display:none;" id="p_p_1"></td>
		</tr>
		<tr>
			<td style="width:40%;"><input name="post[step][a2]" type="text" value="{$a2}" id="a2"/></td>
			<td style="width:40%;"><input name="post[step][p2]" type="text" value="{$p2}" id="p2"/></td>
			<td style="display:none;" id="p_a_2"></td>
			<td style="display:none;" id="p_p_2"></td>
		</tr>
		<tr>
			<td style="width:40%;"><input name="post[step][a3]" type="text" value="{$a3}" id="a3"/></td>
			<td style="width:40%;"><input name="post[step][p3]" type="text" value="{$p3}" id="p3"/></td>
			<td style="display:none;" id="p_a_3"></td>
			<td style="display:none;" id="p_p_3"></td>
		</tr>
		<tr>
			<td class="f_gray" colspan="2">填写示例：阶梯价格 / 非阶梯价格</td>
		</tr>
	</table>
</div>

<p>商品库存<em>*</em><b id="damount"></b></p>
<div><input name="post[amount]" type="text" value="{$amount}" id="amount" style="width:20%"> <input name="post[unit]" type="text" value="{if $unit}{$unit}{else}件{/if}" id="unit" title="计量单位" style="width:10%"/></div>

<p>商品品牌</p>
<div><input name="post[brand]" type="text" id="brand" value="{$brand}"/></div>

<p>商品图片<em>*</em><b id="dthumb"></b></p>
<div>
<input type="hidden" name="post[thumb]" id="thumb0"/>
<input type="hidden" name="post[thumb1]" id="thumb1"/>
<input type="hidden" name="post[thumb2]" id="thumb2"/>
<div class="ui-form-album-show" id="album0" onclick="album_action(0);"></div>
<div class="ui-form-album-show" id="album1" onclick="album_action(1);"></div>
<div class="ui-form-album-show" id="album2" onclick="album_action(2);"></div>
<div class="ui-form-album-upload"><div id="album-picker"></div></div>
</div>
{if $CP}
<script type="text/javascript">
var property_catid = {$catid};
var property_itemid = {$itemid};
var property_admin = 0;
</script>
<script type="text/javascript" src="{DT_STATIC}file/script/property.js"></script>
<section id="load_property" style="display:none;"></section>
{/if}
{if $FD}{fields_html('', '', $item)}{/if}

<p>详细内容<em>*</em><b id="dcontent"></b></p>
</div>
<input type="hidden" name="post[content]" id="content"/>
<ul class="ui-editor-toolbar">
<li class="ui-editor-img"><div id="editor-picker"></div></li>
<li class="ui-editor-bold" id="editor-bold" editor-action="bold">B</li>
<li class="ui-editor-italic" id="editor-italic" editor-action="italic">I</li>
<li class="ui-editor-underline" id="editor-underline" editor-action="underline">U</li>
</ul>
<div class="ui-editor-content" id="editor">{$content}</div>
<script type="text/javascript" src="{DT_MOB}static/js/editor.js"></script>
<script type="text/javascript">
$(function(){
    $('#editor').DEditor({
        editorid: 'editor',
        textareaid: 'content',
        server:'{DT_MOB}upload.php?moduleid={$moduleid}&action=webuploader&from=editor'
    });
});
</script>
<div class="ui-form">

<p>可选属性</p>
<div>
<table cellspacing="1">
<tr>
<th>属性名称</th>
<th>属性值</th>
</tr>
<tr>
<td style="width:35%;"><input name="post[n1]" type="text" value="{$n1}" id="n1"/></td>
<td style="width:50%;"><input name="post[v1]" type="text" value="{$v1}" id="v1"/></td>
</tr>
<tr>
<td style="width:35%;"><input name="post[n2]" type="text" value="{$n2}" id="n2"/></td>
<td style="width:50%;"><input name="post[v2]" type="text" value="{$v2}" id="v2"/></td>
</tr>
<tr>
<td style="width:35%;"><input name="post[n3]" type="text" value="{$n3}" id="n3"/></td>
<td style="width:50%;"><input name="post[v3]" type="text" value="{$v3}" id="v3"/></td>
</tr>
</table>
</div>
<p>运费设置</p>
<div>
<table cellspacing="1">
<tr>
<th>快递</th>
<th>默认运费</th>
<th>每件增加</th>
</tr>
<tr>
<td style="width:40%;"><input name="post[express_name_1]" type="text" value="{$express_name_1}" id="express_name_1"/></td>
<td style="width:20%;"><input name="post[fee_start_1]" type="text" value="{$fee_start_1}" id="fee_start_1"/></td>
<td style="width:20%;"><input name="post[fee_step_1]" type="text" value="{$fee_step_1}" id="fee_step_1"/></td>
</tr>
<tr>
<td style="width:40%;"><input name="post[express_name_2]" type="text" value="{$express_name_2}" id="express_name_2"/></td>
<td style="width:20%;"><input name="post[fee_start_2]" type="text" value="{$fee_start_2}" id="fee_start_2"/></td>
<td style="width:20%;"><input name="post[fee_step_2]" type="text" value="{$fee_step_2}" id="fee_step_2"/></td>
</tr>
<tr>
<td style="width:40%;"><input name="post[express_name_3]" type="text" value="{$express_name_3}" id="express_name_3"/></td>
<td style="width:20%;"><input name="post[fee_start_3]" type="text" value="{$fee_start_3}" id="fee_start_3"/></td>
<td style="width:20%;"><input name="post[fee_step_3]" type="text" value="{$fee_step_3}" id="fee_step_3"/></td>
</tr>
</table>
</div>
<p>我的推荐</p>
<div>
<input type="radio" name="post[elite]" value="1" id="elite_1" {if $elite} checked{/if}><label for="elite_1">是</label><br/>
<input type="radio" name="post[elite]" value="0" id="elite_0" {if !$elite} checked{/if}><label for="elite_0">否</label><br/>
</div>
{if $fee_add}
<p>发布此信息需消费</p>
<div><span class="f_b f_red">{$fee_add}</span> {$fee_unit}</div>
{if $fee_currency == 'money'}
<p>{$DT[money_name]}余额</p>
<div><span class="f_blue f_b">{$_money}{$fee_unit}</span> <a href="charge.php?action=pay" class="b">[充值]</a></div>
{else}
<p>{$DT[credit_name]}余额</p>
<div><span class="f_blue f_b">{$_credit}{$fee_unit}</span> <a href="credit.php?action=buy" class="b">[购买]</a></div>
{/if}
{/if}

{if $need_password}
<p>支付密码<em>*</em><b id="dpassword"></b></p>
<div><input type="password" name="password" value="" id="password" autocomplete="off"/></div>
{/if}

{if $need_question}
<p>验证问题<em>*</em><b id="danswer"></b></p>
<div>{template 'question', 'chip'}</div>
{/if}
{if $need_captcha}
<p>验证码<em>*</em><b id="dcaptcha"></b></p>
<div>{template 'captcha', 'chip'}</div>
{/if}

<div class="blank-16"></div>
<input type="submit" name="submit" value="{if $action == 'edit'}修改{else}发布{/if}" class="btn-blue"/>
<div class="blank-32"></div>
</div>
</form>
<script type="text/javascript">
function album_action(id) {
	Dsheet('<a href="javascript:album_delete('+id+');"><span style="color:red;">删除图片</span></a>', '取消', '确定要删除图片吗？');
}
function album_delete(id) {
	$('#thumb'+id).val('');
	$('#album'+id).html('');
	$('#album'+id).hide();
	$('.ui-form-album-upload').show();	
}
function album_show(id, url) {
	$('#thumb'+id).val(url);
	$('#album'+id).html('<img src="'+url+'"/>');
	$('#album'+id).show();
}
var albumu = WebUploader.create({
	auto: true,
    server: '{DT_MOB}upload.php?moduleid={$moduleid}&action=webuploader&from=album&width=100&height=100',
    pick: '#album-picker',
    accept: {
        title: 'Images',
        extensions: 'gif,jpg,jpeg,bmp,png',
        mimeTypes: 'image/*'
    },
    resize: false
});
albumu.on('fileQueued', function(file) {
    Dtoast('上传中..', '', 30);
});
albumu.on('uploadProgress', function(file, percentage) {
	var p = parseInt(percentage * 100);
	$('.ui-toast').html(p > 99 ? '处理中...' : '上传中...'+p+'%');
});
albumu.on( 'uploadSuccess', function(file, data) {
	if(data.error) {
		Dtoast(data.message, '', 5);
	} else {
		var id = 3;
		if($('#thumb0').val() == '') {
			id = 0;
		} else if($('#thumb1').val() == '') {
			id = 1;
		} else if($('#thumb2').val() == '') {
			id = 2;
		}
		if(id < 3) album_show(id, data.url);
		if($('#thumb0').val() && $('#thumb1').val() && $('#thumb2').val()) $('.ui-form-album-upload').hide();
	}
});
albumu.on( 'uploadError', function(file, data) {
    Dtoast(data.message, '', 5);
});
albumu.on('uploadComplete', function(file) {
    $('.ui-toast').hide();
});
{if $thumb || $thumb1 || $thumb2}
$(function(){
	{if $thumb}album_show(0, '{$thumb}');{/if}
	{if $thumb1}album_show(1, '{$thumb1}');{/if}
	{if $thumb2}album_show(2, '{$thumb2}');{/if}
	{if $thumb && $thumb1 && $thumb2}$('.ui-form-album-upload').hide();{/if}
});
{/if}
</script>
{load('clear.js')}
{else}
<div class="ui-form sch">
<form action="?">
<input type="hidden" name="mid" value="{$mid}"/>
<input type="hidden" name="status" value="{$status}"/>
<div><input type="search" name="kw" value="{$kw}" placeholder="输入关键词搜索"/></div>
</form>
</div>
{if $_userid}
<div class="list-menu">
	<ul>
	<a href="?mid={$mid}&status=3"><li{if $status==3} class="on"{/if} id="s3">已发布{if !$kw} {$nums[3]}{/if}</li></a>
	<a href="?mid={$mid}&status=2"><li{if $status==2} class="on"{/if} id="s2">审核中{if !$kw} {$nums[2]}{/if}</li></a>
	<a href="?mid={$mid}&status=1"><li{if $status==1} class="on"{/if} id="s1">未通过{if !$kw} {$nums[1]}{/if}</li></a>
	<a href="?mid={$mid}&status=4"><li{if $status==4} class="on"{/if} id="s4">已下架{if !$kw} {$nums[4]}{/if}</li></a>
	</ul>
</div>
{/if}
<form method="post">
{if $lists}
{loop $lists $v}
<div class="list-img">
<input type="checkbox" name="itemid[]" value="{$v[itemid]}" class="dsn" id="checkbox-{$v[itemid]}"/>
<a href="{$v[linkurl]}"><img src="{if $v[thumb]}{$v[thumb]}{else}{DT_MOB}static/img/80x60.png{/if}" width="80" height="60" alt="" onerror="this.src='{DT_MOB}static/img/80x60.png';"/></a>
<ul>
<li><em class="check" id="check-{$v[itemid]}"></em><a href="?mid={$mid}&action=edit&itemid={$v[itemid]}" rel="external"><strong>{$v[title]}</strong></a></li>
<li><em class="sheet" id="sheet-{$v[itemid]}"></em><span>{$v[date]}</span></li>
</ul>
</div>
{/loop}
{/if}
{if $pages}<div class="pages">{$pages}</div>{/if}
<div id="foot-bar" class="dsn">
<div class="foot-bar-fix"></div>
<div class="foot-bar btns">
{if $timetype!='add'}<input type="submit" value="刷新选中" class="btn-green" onclick="this.form.action='?mid={$mid}&status={$status}&action=refresh';"/>{/if}
{if $status==3}<input type="submit" value="批量下架" class="btn-green" onclick="this.form.action='?mid={$mid}&status={$status}&action=unsale';"/>{/if}
{if $status==4}<input type="submit" value="批量上架" class="btn-green" onclick="this.form.action='?mid={$mid}&status={$status}&action=onsale';"/>{/if}
{if $MG[delete]}<input type="submit" name="submit" value="删除选中" class="btn-red" onclick="if(confirm('确定要删除选中{$MOD[name]}吗？')){this.form.action='?mid={$mid}&status={$status}&action=delete'}else{return false;}"/>{/if}
</div>
</div>
</form>
<script type="text/javascript">
$(function(){
	if($('#foot-bar input').length == 0) $('.check').hide();
	$('.list-img em').click(function() {
		if($(this).attr('class') == 'sheet') {
			var id = $(this).attr('id').replace('sheet-', '');
			Dsheet('<a href="?mid={$mid}&action=edit&itemid='+id+'"><span>修改</span></a>|<a href="?mid={$mid}&action=relate&itemid='+id+'"><span>关联</span></a>{if $MG[copy]}|<a href="?mid={$mid}&action=add&itemid='+id+'"><span>复制</span></a>{/if}{if $MG[delete]}|<a href="?mid={$mid}&action=delete&itemid='+id+'" onclick="return _delete();"><span style="color:red;">删除</span></a>{/if}', '取消');
		} else {
			var id = $(this).attr('id').replace('check-', '');
			if($('#checkbox-'+id).attr('checked')) {
				$('#checkbox-'+id).attr('checked', false);
				$(this).attr('class', 'check');
			} else {
				$('#checkbox-'+id).attr('checked', true);
				$(this).attr('class', 'checked');
			}
			if($('.checked').length > 0) {
				$('#foot-bar').fadeIn(300);
			} else {
				$('#foot-bar').fadeOut(300);
			}
		}
	});
});
</script>
{/if}
{if $action == 'add' || $action == 'edit'}
<script type="text/javascript">
function _p() {
	if(Dd('tag').value) {
		Ds('reccate');
	}
}
function check() {
	var l;
	var f;
	f = 'catid_1';
	if(Dd(f).value == 0) {
		Dmsg('请选择商品分类', 'catid', 1);
		return false;
	}
	f = 'title';
	l = Dd(f).value.length;
	if(l < 2) {
		Dmsg('商品名称最少2字，当前已输入'+l+'字', f);
		return false;
	}
	f = 'amount';
	l = Dd(f).value;
	if(l < 1) {
		Dmsg('请填写库存', f);
		return false;
	}
	{if $DT_PC}
	f = 'thumb';
	l = Dd(f).value.length;
	if(l < 10) {
		Dmsg('请上传第一张商品图片', f);
		return false;
	}
	{/if}
	f = 'thumb0';
	l = Dd(f).value.length;
	if(l < 10) {
		Dmsg('请上传第一张商品图片', f);
		return false;
	}
	f = 'content';
	l = Dd(f).value.length;
	if(l < 15 || l > 50000) {
		Dmsg('详细内容应为15-50000字，当前已输入'+l+'字', f);
		return false;
	}
	if(Dd('v1').value) {
		if(!Dd('n1').value) {
			Dmsg('请填写属性名称', 'nv');
			Dd('n1').focus();
			return false;
		}
		if(Dd('v1').value.indexOf('|') == -1) {
			Dmsg(Dd('n1').value+'至少需要两个属性', 'nv');
			Dd('v1').focus();
			return false;
		}
	}
	if(Dd('v2').value) {
		if(!Dd('n2').value) {
			Dmsg('请填写属性名称');
			Dd('n2').focus();
			return false;
		}
		if(Dd('v2').value.indexOf('|') == -1) {
			Dmsg(Dd('n2').value+'至少需要两个属性', 'nv');
			Dd('v2').focus();
			return false;
		}
	}
	if(Dd('v3').value) {
		if(!Dd('n3').value) {
			Dmsg('请填写属性名称', 'nv');
			Dd('n3').focus();
			return false;
		}
		if(Dd('v3').value.indexOf('|') == -1) {
			Dmsg(Dd('n3').value+'至少需要两个属性', 'nv');
			Dd('v3').focus();
			return false;
		}
	}
	if(Dd('n1').value && (Dd('n1').value == Dd('n2').value || Dd('n1').value == Dd('n3').value)) {
		Dmsg('属性名称不能重复', 'nv');
		return false;
	}
	if(Dd('n2').value && (Dd('n2').value == Dd('n1').value || Dd('n2').value == Dd('n3').value)) {
		Dmsg('属性名称不能重复', 'nv');
		return false;
	}
	if(Dd('n3').value && (Dd('n3').value == Dd('n1').value || Dd('n3').value == Dd('n2').value)) {
		Dmsg('属性名称不能重复', 'nv');
		return false;
	}
	if(Dd('express_name_1').value && (Dd('express_name_1').value == Dd('express_name_2').value || Dd('express_name_1').value == Dd('express_name_3').value)) {
		Dmsg('快递名称不能重复', 'express');
		return false;
	}
	if(Dd('express_name_2').value && (Dd('express_name_2').value == Dd('express_name_1').value || Dd('express_name_2').value == Dd('express_name_3').value)) {
		Dmsg('快递名称不能重复', 'express');
		return false;
	}
	if(Dd('express_name_3').value && (Dd('express_name_3').value == Dd('express_name_1').value || Dd('express_name_3').value == Dd('express_name_2').value)) {
		Dmsg('快递名称不能重复', 'express');
		return false;
	}
	{if $FD}{fields_js()}{/if}
	{if $CP}{property_js()}{/if}
{if $need_password}
	f = 'password';
	l = Dd(f).value.length;
	if(l < 6) {
		Dmsg('请填写支付密码', f);
		return false;
	}
{/if}
{if $need_question}
	f = 'answer';
	if($('#c'+f).html().indexOf('ok.png') == -1) {
		Dmsg('请填写正确的验证问题', f);
		return false;
	}
{/if}
{if $need_captcha}
	f = 'captcha';
	if($('#c'+f).html().indexOf('ok.png') == -1) {
		Dmsg('请填写正确的验证码', f);
		return false;
	}
{/if}
return Dstep();
}
function Dexpress(i, s) {
	if(Dd('express_'+i).value > 0) {
		var t1 = s.split('[');
		var t2 = t1[1].split(',');
		Dd('express_name_'+i).value = t2[0];
		Dd('fee_start_'+i).value = t2[1];
		Dd('fee_step_'+i).value = t2[2];
	} else {
		Dd('express_name_'+i).value = '';
		Dd('fee_start_'+i).value = '';
		Dd('fee_step_'+i).value = '';
	}
}
function Nexpress(i, s) {
	Dd('express_name_1').value = s;
	Dd('fee_start_1').value = i;
	Dd('fee_step_1').value = '0.00';
	$('#express_1').val(0);
	Dd('express_name_2').value = '';
	Dd('fee_start_2').value = '0.00';
	Dd('fee_step_2').value = '0.00';
	$('#express_2').val(0);
	Dd('express_name_3').value = '';
	Dd('fee_start_3').value = '0.00';
	Dd('fee_step_3').value = '0.00';
	$('#express_3').val(0);
}

function Dstep() {
	Dd('p_a_1').innerHTML=Dd('p_p_1').innerHTML=Dd('p_a_2').innerHTML=Dd('p_p_2').innerHTML=Dd('p_a_3').innerHTML=Dd('p_p_3').innerHTML='';
	var a1 = parseInt(Dd('a1').value);
	var p1 = parseFloat(Dd('p1').value);
	var a2 = parseInt(Dd('a2').value);
	var p2 = parseFloat(Dd('p2').value);
	var a3 = parseInt(Dd('a3').value);
	var p3 = parseFloat(Dd('p3').value);
	var u = Dd('unit').value;
	if(u.length < 1) Dd('unit').value = u = '件';
	var m = '{$DT[money_unit]}';
	if(!a1 || a1 < 1) {
		Dmsg('起订量必须大于0');
		Dd('a1').value = '1';
		Dd('a1').focus();
		return false;
	}
	if(!p1 || p1 < 0.1) {
		Dmsg('请填写商品价格');
		Dd('p1').value = '';
		Dd('p1').focus();
		return false;
	}
	Dd('p_a_1').innerHTML = a1+u+'以上';
	Dd('p_p_1').innerHTML = p1+m+'/'+u;
	if(a2 > 1 && p2 > 0.01) {
		if(a2 <= a1) {
			Dmsg('数量必须大于'+a1);
			Dd('a2').value = '';
			Dd('a2').focus();
			return false;
		}
		if(p2 >= p1) {
			Dmsg('价格必须小于'+p1);
			Dd('p2').value = '';
			Dd('p2').focus();
			return false;
		}
		Dd('p_a_1').innerHTML = a1+'-'+a2+u;
		Dd('p_p_1').innerHTML = p1+m+'/'+u;
		Dd('p_a_2').innerHTML = '>'+a2+u;
		Dd('p_p_2').innerHTML = p2+m+'/'+u;
	}
	if(a3 > 1 && p3 > 0.01) {
		if(a3 <= a2) {
			Dmsg('数量必须大于'+a2);
			Dd('a3').value = '';
			Dd('a3').focus();
			return false;
		}
		if(p3 >= p2) {
			Dmsg('价格必须小于'+p2);
			Dd('p3').value = '';
			Dd('p3').focus();
			return false;
		}
		Dd('p_a_2').innerHTML = (a2+1)+'-'+a3+u;
		Dd('p_p_2').innerHTML = p2+m+'/'+u;
		Dd('p_a_3').innerHTML = '>'+a3+u;
		Dd('p_p_3').innerHTML = p3+m+'/'+u;
	}
	return true;
}

var destoon_oauth = '{$EXT[oauth]}';
</script>
{/if}
{template 'footer', 'member'}